import type {
  MenuAddDTOType,
  MenuUpdateDTOType,
  MenuSearchDTOType,
} from '@/resources/interface/menu/MenuTypes'
import type { TableColumn } from '@/components/CommonTable.vue'
import { ComponentEnum, type FormItemConfig } from '@/components/CommonDialogForm.vue'
import { markRaw } from 'vue'
import IconPicker from '@/components/IconPicker.vue'

/**
 * 菜单表 参数对象
 */
export class MenuParams {
  /**
   * 表单参数
   */
  static formColumn: FormItemConfig[] = [
    {
      label: '菜单名',
      prop: 'name',
      type: ComponentEnum.INPUT,
      field: 'name',
    },
    {
      label: '菜单图标',
      prop: 'icon',
      type: ComponentEnum.CUSTOMIZE,
      field: 'icon',
      component: markRaw(IconPicker),
    },
    {
      label: '路由访问路径',
      prop: 'router',
      type: ComponentEnum.INPUT,
      field: 'router',
    },
    {
      label: '组件文件路径',
      prop: 'component',
      type: ComponentEnum.INPUT,
      field: 'component',
    },
    {
      label: '菜单节点',
      prop: 'type',
      type: ComponentEnum.SELECT,
      field: 'type',
      options: [
        {
          label: '叶子节点',
          value: 0,
          size: 'default',
        },
        {
          label: '中间节点',
          value: 1,
          size: 'default',
        },
      ],
    },
    {
      label: '父节点',
      prop: 'parentId',
      type: ComponentEnum.SELECT,
      field: 'parentId',
      attribute: {
        size: 'default',
      },
      options: [],
    },
    {
      label: '菜单状态',
      prop: 'status',
      type: ComponentEnum.RADIO_GROUP,
      field: 'status',
      options: [
        {
          label: '启用',
          value: 0,
          size: 'default',
        },
        {
          label: '禁用',
          value: 1,
          size: 'default',
        },
      ],
    },
    {
      label: '排序',
      prop: 'sort',
      type: ComponentEnum.INPUT_NUMBER,
      field: 'sort',
    },
  ]
  /**
   * 表格参数
   */
  static tableColumn: TableColumn[] = [
    {
      label: '菜单名',
      field: 'name',
    },
    {
      label: '菜单图标',
      field: 'icon',
    },
    {
      label: '路由访问路径',
      field: 'router',
    },
    {
      label: '菜单类型',
      field: 'type',
      formatter(row) {
        return row.type === 0 ? '叶子节点' : row.type === 1 ? '中间节点' : '根节点'
      },
    },
    {
      label: '路由状态',
      field: 'status',
      formatter(row) {
        return row.status === 0 ? '启用' : '禁用'
      },
    },
    {
      label: '组件文件路径',
      field: 'component',
    },
    {
      label: '排序',
      field: 'sort',
    },
    {
      label: '操作',
      field: 'right',
      attribute: {
        fixed: 'right',
        width: '200px',
      },
      template: {
        options: [
          {
            icon: 'edit',
            type: 'primary',
            size: 'small',
            method: 'update',
          },
          {
            icon: 'delete',
            type: 'danger',
            size: 'small',
            method: 'remove',
          },
        ],
      },
    },
  ]
  /**
   * 添加对象
   */
  static addDTO: MenuAddDTOType = {
    name: '',
    icon: '',
    router: '',
    type: 0,
    parentId: 0,
    status: 0,
    component: '',
    sort: 0,
  }
  /**
   * 修改对象
   */
  static updateDTO: MenuUpdateDTOType = {
    id: 0,
    name: '',
    icon: '',
    router: '',
    type: 0,
    parentId: 0,
    status: 0,
    component: '',
    sort: 0,
  }
  /**
   * 查询对象
   */
  static searchDTO: MenuSearchDTOType = {
    page: {
      current: 1,
      size: 20,
    },
  }
}
